package com.zpark.oop.day03;

/**
 * @PackageName: com.zpark.oop.day03
 * @ClassName: Student
 * @Description:
 * @author: RZS
 * @date: 2024/10/8  17:29
 */
public class Student {
    private String name;
    private int age;
    // 设置属性的方法
    public void setName(String name) {
        // 校验name值是否符合需求
        this.name = name;
    }
    // 获取属性的方法
    public String getName() {
        return name;
    }

    public void setAge(int age) {
        if (age >= 0 && age <= 120) {
            this.age = age;
        } else {
            System.err.println("年龄不合法");
        }
    }

    public int getAge() {
        return age;
    }



    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
